﻿Imports TNCDAL
Imports System

Public Class ucThongkeTongGiaMuaBan
    Dim ms As New MStatisticsPriceFile
    Dim uti As New Utilities
    Dim isdata As Boolean = False
    Dim istype As Boolean = False
    Private Sub frmThongkeTongGiaMuaBan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadImport()
        'Dim query = ms.getFileFeeList(cbFeeType.SelectedValue, cbCustomer.SelectedValue)
        'grid.DataSource = query
        BindingGrid()
    End Sub
    Private Sub LoadImport()
        uti.FillAllCustomerCombo(cbCustomer, chkIsExport.Checked)

        isdata = True
        istype = True
    End Sub
    Private Sub BindingGrid()
        Try
            Dim query = ms.getFileFeeList(chkIsExport.Checked) ' ms.getFileFeeList(cbFeeType.SelectedValue, cbCustomer.SelectedValue)
            grid.DataSource = query
            'If grid.RowCount > 0 Then
            FormatGrid()
            'End If
            grid.Columns(0).Visible = False
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    
        'If cbCustomer.SelectedValue = 0 Then
        '    'tất cả khách hàng
        'grid.Columns(0).Visible = False
        '    grid.Columns(2).Visible = True
        'Else
        '    grid.Columns(0).Visible = False
        '    grid.Columns(2).Visible = False
        'End If


    End Sub
    Private Sub FormatGrid()

        For index = 3 To grid.ColumnCount - 1
            grid.Columns(index).DefaultCellStyle.Format = "#,##0.##"
            grid.Columns(index).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next

    End Sub
    Private Sub grid_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles grid.CellFormatting
        '' First row always displays
        'If e.RowIndex = 0 Then
        '    Return
        'End If
        'If IsRepeatedCellValue(e.RowIndex, e.ColumnIndex) Then
        '    e.Value = String.Empty
        '    e.FormattingApplied = True
        'End If
    End Sub
    Private Function IsRepeatedCellValue(ByVal rowIndex As Integer, ByVal colIndex As Integer) As Boolean
        Dim currCell As DataGridViewCell = grid.Rows(rowIndex).Cells(colIndex)
        Dim prevCell As DataGridViewCell = grid.Rows(rowIndex - 1).Cells(colIndex)
        If (currCell.Value Is prevCell.Value) OrElse (currCell.Value IsNot Nothing AndAlso prevCell.Value IsNot Nothing AndAlso currCell.Value.ToString() = prevCell.Value.ToString()) Then
            Return True
        Else
            Return False
        End If
    End Function

   

    Private Sub cbCustomer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

        If isdata Then
            'Nếu đã load dữ liệu
            BindingGrid()
        End If

    End Sub

   
   

    Private Sub cbFeeType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

        If istype Then
            BindingGrid()
        End If

    End Sub

    
    
    Private Sub cbCustomer_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbCustomer.SelectedIndexChanged

        If isdata Then
            LoadImport()
            BindingGrid()
        End If

    End Sub

  
    Private Sub chkIsExport_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkIsExport.CheckedChanged

        If isdata Then
            LoadImport()
            BindingGrid()
        End If

    End Sub
End Class